export const state = () => ({
  user: {
    userName: '',
    userId: '',
  }
});

export const mutations = {
  USER_LOGIN(state, user) {
    state.user = user;
    // 存储登陆信息
    window.sessionStorage.setItem('user', JSON.stringify((user)));
  },
  USER_EXIT(state) {
    state.user = {};
    window.sessionStorage.removeItem('user');
  }
}

export const actions = {
  // 用户登录
  login({
    commit
  }, data) {
    commit('USER_LOGIN', data);
  },
  // 用户退出
  exit({
    commit
  }) {
    commit('USER_EXIT');
  },
};
